package top.forlenet.service.impl;



import top.forlenet.dao.SignDao;
import top.forlenet.dao.impl.SignDaoImpl;
import top.forlenet.entity.Sign;
import top.forlenet.service.SignService;
import top.forlenet.vo.InviteVO;
import top.forlenet.vo.SignVO;

import java.util.List;
import java.util.Random;

public class SignServiceImpl implements SignService {

    private SignDao signDao = new SignDaoImpl();

    @Override
    public void sign(Integer uid) {

        int count = signDao.todaySignCount(uid);
        if (count > 0) {
            throw new RuntimeException("用户已签到");
        }
        Sign sign = new Sign();
        sign.setUid(uid);
        sign.setPoint(new Random().nextInt(9) + 2);
        signDao.insert(sign);
    }

    @Override
    public List<SignVO> listSignInfo(Integer uid) {
        return signDao.selectList(uid);
    }

    @Override
    public List<InviteVO> listInviteInfo(Integer uid) {
        return signDao.sumPoint(uid);
    }
}
